import prompt from '@system.prompt';
import http from '@ohos.net.http';
import router from '@system.router';
export default {
    data: {
        title: 'World',
        user: {
            "userName": null, "userPassword": null,
            "userQuestion": null, "userAnswer": null
        },
    },


    inputUserNameChange(event){
        this.user.userName=event.value;

    },

    inputPasswordChange(event){
        this.user.userPassword=event.value;
    },

    problem(event){
        this.user.userQuestion=event.value;
    },


    problemAnswer(event){
        this.user.userAnswer=event.value;
    },

    register(){
        // 每一个httpRequest对应一个http请求任务，不可复用
        let httpRequest = http.createHttp();

        httpRequest.request(
        // 填写http请求的url地址，可以带参数也可以不带参数。URL地址需要开发者自定义。GET请求的参数可以在extraData中指定
            this.$app.$def.getUserRegisterUrl(),
            {
                method: 'POST',
                extraData: JSON.stringify(this.user)
            }, (err, data) => {
            if (!err) {
                // data.result为http响应内容，可根据业务需要进行解析
                console.info('Result:' + data.result);
                console.log("--------->")
                this.$app.$def.globalData.jsonResult = JSON.parse(data.result);
                console.info('code:' + this.$app.$def.globalData.jsonResult.code);
                console.info('msg:' + this.$app.$def.globalData.jsonResult.msg);
                if(this.$app.$def.globalData.jsonResult.code == 1){
                    router.push({
                        uri:"pages/login/login",

                    })
                }
                else{
                    prompt.showToast({
                        message:this.$app.$def.globalData.jsonResult.msg,
                        duration: 2000,
                    });

                }
                // data.header为http响应头，可根据业务需要进行解析
                console.info('header:' + data.header);
            } else {
                console.info('error:' + err.data);
            }
        }
        );
    },
}
